
//
//  CJUIKit.m
//  DatangLife
//
//  Created by 陈建 on 2018/5/7.
//  Copyright © 2018年 DatangLife. All rights reserved.
//

#import "CJUIKit.h"
#import <SVProgressHUD.h>
@implementation CJUIKit

+(UIView *)viewcornerRadius:(float)radius andColor:(UIColor *)color andWidth:(float)width onView:(UIView *)view
{
    view.layer.cornerRadius = radius;
    view.layer.borderColor = color.CGColor;
    view.layer.borderWidth = width;
    [view.layer setMasksToBounds:YES];
    return view;
}

+(UILabel *)labelWithBackgroundColor:(UIColor *)backgrountColor textColor:(UIColor *)textColor textAlignment:(NSTextAlignment)textAlignment numberOfLines:(NSInteger)numberOfLines fontSize:(float)size font:(UIFont *)font text:(NSString *)text
{
    UILabel *label = [[UILabel alloc] init];
    if (backgrountColor) {
        label.backgroundColor = backgrountColor;
    }
    if (textColor) {
        label.textColor = textColor;
    }
    if (text) {
        label.text = text;
    }
    label.numberOfLines = numberOfLines;
    label.textAlignment = textAlignment;
    if (size>0) {
        label.font = [UIFont systemFontOfSize:size];
    }else
        label.font = font;
    return label;
}

+(UITextField *)textFieldWithBackgroundColor:(UIColor *)backgrountColor textColor:(UIColor *)textColor secureTextEntry:(BOOL)secureTextEntry fontSize:(float)size font:(UIFont *)font text:(NSString *)text placeholder:(NSString *)placeholder textAlignment:(NSTextAlignment)textAlignment
{
    UITextField *textField = [[UITextField alloc] init];
    if (backgrountColor) {
        textField.backgroundColor = backgrountColor;
    }
    if (textColor) {
        textField.textColor = textColor;
    }
    if (text) {
        textField.text = text;
    }
    if (placeholder) {
        textField.placeholder = placeholder;
    }
    if (size>0) {
        textField.font = [UIFont systemFontOfSize:size];
    }else
        textField.font = font;
    textField.secureTextEntry = secureTextEntry;
    textField.textAlignment = textAlignment;
    return textField;
}

+(UIButton *)buttonWithBackgroundColor:(UIColor *)backgrountColor titleColorForNormal:(UIColor *)titleColorForNormal titleForNormal:(NSString *)titleForNormal titleForSelete:(NSString *)titleForSelete titleColorForSelete:(UIColor *)titleColorForSelete  fontSize:(float)size font:(UIFont *)font backgroundImageForNormal:(NSString *)backgroundImageForNormal backgroundImageForSelete:(NSString *)backgroundImageForSelete imageForNormal:(NSString *)imageForNormal imageForSelete:(NSString *)imageForSelete
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (backgrountColor) {
        [button setBackgroundColor:backgrountColor];
    }
    if (titleForNormal) {
        [button setTitle:titleForNormal forState:0];
    }
    if (titleForSelete) {
        [button setTitle:titleForSelete forState:UIControlStateSelected];
    }
    if (titleColorForNormal) {
        [button setTitleColor:titleColorForNormal forState:0];
    }
    if (titleColorForSelete) {
        [button setTitleColor:titleColorForSelete forState:UIControlStateSelected];
    }
    if (size>0) {
        button.titleLabel.font = [UIFont systemFontOfSize:size];
    }else
        button.titleLabel.font = font;
    if (backgroundImageForNormal) {
        [button setBackgroundImage: [UIImage imageNamed:backgroundImageForNormal] forState:0];
    }
    if (backgroundImageForSelete) {
        [button setBackgroundImage: [UIImage imageNamed:backgroundImageForSelete] forState:UIControlStateSelected];
    }
    if (imageForNormal) {
        [button setImage: [UIImage imageNamed:imageForNormal] forState:0];
    }
    if (imageForSelete) {
        [button setImage: [UIImage imageNamed:imageForSelete] forState:UIControlStateSelected];
    }
    return button;
}

+(UIButton *)buttonWithBackgroundColor:(UIColor *)backgrountColor titleColorForNormal:(UIColor *)titleColorForNormal titleForNormal:(NSString *)titleForNormal titleForSelete:(NSString *)titleForSelete titleColorForSelete:(UIColor *)titleColorForSelete  fontSize:(float)size font:(UIFont *)font imageForNormal:(NSString *)imageForNormal imageForSelete:(NSString *)imageForSelete
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    if (backgrountColor) {
        [button setBackgroundColor:backgrountColor];
    }
    if (titleForNormal) {
        [button setTitle:titleForNormal forState:0];
    }
    if (titleForSelete) {
        [button setTitle:titleForSelete forState:UIControlStateSelected];
    }
    if (titleColorForNormal) {
        [button setTitleColor:titleColorForNormal forState:0];
    }
    if (titleColorForSelete) {
        [button setTitleColor:titleColorForSelete forState:UIControlStateSelected];
    }
    if (size>0) {
        button.titleLabel.font = [UIFont systemFontOfSize:size];
    }else
        button.titleLabel.font = font;
    if (imageForNormal) {
        [button setImage: [UIImage imageNamed:imageForNormal] forState:0];
    }
    if (imageForSelete) {
        [button setImage: [UIImage imageNamed:imageForSelete] forState:UIControlStateSelected];
    }
    return button;
}


+(UIButton *)buttonWithTitleColorForNormal:(UIColor *)titleColorForNormal titleForNormal:(NSString *)titleForNormal titleForSelete:(NSString *)titleForSelete titleColorForSelete:(UIColor *)titleColorForSelete  fontSize:(float)size font:(UIFont *)font backgroundImageForNormal:(NSString *)backgroundImageForNormal backgroundImageForSelete:(NSString *)backgroundImageForSelete
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (titleForNormal) {
        [button setTitle:titleForNormal forState:0];
    }
    if (titleForSelete) {
        [button setTitle:titleForSelete forState:UIControlStateSelected];
    }
    if (titleColorForNormal) {
        [button setTitleColor:titleColorForNormal forState:0];
    }
    if (titleColorForSelete) {
        [button setTitleColor:titleColorForSelete forState:UIControlStateSelected];
    }
    if (size>0) {
        button.titleLabel.font = [UIFont systemFontOfSize:size];
    }else
        button.titleLabel.font = font;
    if (backgroundImageForNormal) {
        [button setBackgroundImage: [UIImage imageNamed:backgroundImageForNormal] forState:0];
    }
    if (backgroundImageForSelete) {
        [button setBackgroundImage: [UIImage imageNamed:backgroundImageForSelete] forState:UIControlStateSelected];
    }
    return button;
}

+(UIButton *)buttonWithBackgroundColor:(UIColor *)backgrountColor titleColorForNormal:(UIColor *)titleColorForNormal titleForNormal:(NSString *)titleForNormal titleForSelete:(NSString *)titleForSelete titleColorForSelete:(UIColor *)titleColorForSelete  fontSize:(float)size font:(UIFont *)font
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (titleForNormal) {
        [button setTitle:titleForNormal forState:0];
    }
    if (titleForSelete) {
        [button setTitle:titleForSelete forState:UIControlStateSelected];
    }
    if (titleColorForNormal) {
        [button setTitleColor:titleColorForNormal forState:0];
    }
    if (titleColorForSelete) {
        [button setTitleColor:titleColorForSelete forState:UIControlStateSelected];
    }
    if (size>0) {
        button.titleLabel.font = [UIFont systemFontOfSize:size];
    }else
        button.titleLabel.font = font;
    if (backgrountColor) {
        [button setBackgroundColor:backgrountColor];
    }
    return button;
}

+(UIButton *)buttonWithBackgroundImageForNormal:(NSString *)backgroundImageForNormal backgroundImageForSelete:(NSString *)backgroundImageForSelete
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (backgroundImageForNormal) {
        [button setBackgroundImage: [UIImage imageNamed:backgroundImageForNormal] forState:0];
    }
    
    if (backgroundImageForSelete) {
        [button setBackgroundImage: [UIImage imageNamed:backgroundImageForSelete] forState:UIControlStateSelected];
    }
    
    return button;
}

+(UIButton *)buttonWithBackgroundColor:(UIColor *)backgrountColor imageForNormal:(NSString *)imageForNormal imageForSelete:(NSString *)imageForSelete
{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (backgrountColor) {
        [button setBackgroundColor:backgrountColor];
    }
    if (imageForNormal) {
        [button setImage: [UIImage imageNamed:imageForNormal] forState:0];
    }
    
    if (imageForSelete) {
        [button setImage: [UIImage imageNamed:imageForSelete] forState:UIControlStateSelected];
    }
    
    return button;
}

+(void)showWithString:(NSString *)string
{
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:string];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeCustom]; //设置HUD背景图层的样式
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setBackgroundLayerColor:[UIColor clearColor]];
    [SVProgressHUD dismissWithDelay:1];
//    [SVProgressHUD dismiss];
}

+(void)showErrorWithStatus:(NSString *)string
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setMinimumDismissTimeInterval:0.1];
    [SVProgressHUD showErrorWithStatus:string];
}

+(void)showSuccessWithStatus:(NSString *)string
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD setMinimumDismissTimeInterval:0.1];
    [SVProgressHUD showSuccessWithStatus:string];
}

+ (BOOL)isNullWithString:(NSString *)string{
    if ([string isEqual:@"NULL"] || [string isKindOfClass:[NSNull class]] || [string isEqual:[NSNull null]] || [string isEqual:NULL] || [[string class] isSubclassOfClass:[NSNull class]] || string == nil || string == NULL || [string isKindOfClass:[NSNull class]] || [[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0 || [string isEqualToString:@"<null>"] || [string isEqualToString:@"(null)"]||[string isEqual:[NSNull null]]){
        return YES;
    }else{
        return NO;
    }
}



@end
